import {
  ViewEngineBase,
  ViewController,
  ITabExpPanelController,
  ITabExpViewEvent,
  ITabExpViewState,
} from '@ibiz-template/runtime';
import { IAppDETabExplorerView } from '@ibiz/model-core';

export class TabExpViewEngine extends ViewEngineBase {
  /**
   * 分页面板视图控制器
   *
   * @protected
   * @type {ViewController<
   *         IAppDETabExplorerView,
   *         ITabExpViewState,
   *         ITabExpViewEvent
   *     >}
   * @memberof TabExpViewEngine
   */
  protected declare view: ViewController<
    IAppDETabExplorerView,
    ITabExpViewState,
    ITabExpViewEvent
  >;

  /**
   * 分页导航面板
   *
   * @readonly
   * @memberof TabExpViewEngine
   */
  get tabExpPanel(): ITabExpPanelController {
    return this.view.getController('tabexppanel') as ITabExpPanelController;
  }

  /**
   * 视图created生命周期执行逻辑
   *
   * @return {*}  {Promise<void>}
   * @memberof TabExpViewEngine
   */
  async onCreated(): Promise<void> {
    await super.onCreated();
    const { childNames } = this.view;
    childNames.push('tabexppanel');
    if (!this.view.slotProps.tabexppanel) {
      this.view.slotProps.tabexppanel = {};
    }
    this.view.slotProps.tabexppanel.defaultTabName = this.view.state.srfnav;
  }

  async onMounted(): Promise<void> {
    await super.onMounted();
    await this.loadEntityData();
  }
}
